import { ETaskState } from "GameLoop/DecisionMaking/TaskDeclare/type";
import { ATaskAdapter } from ".";
import { TowerTaskChecker } from "../TaskCheck/TowerTaskChecker";

export class TowerTaskAdapter extends ATaskAdapter<"tower">
{
    constructor(context:IContextGetter,world:WorldGetter)
    {
        super(context,world);
        TowerTaskChecker.notify = this.notify.bind(this);
    }
 
    public bindTasks(room: Room, tasks:ITaskDeclare["tower"][],customCheck:IConditionFunction): void 
    {
        for(const task of tasks)
        {
            if(customCheck(room as Required<Room>,task) == OK )
            {
                room.deleteTaskById(task.id,"tower");
            }
            else if(ETaskState.Complete == this.checkState(room,task))
            {
                //global.Log.Info(`${room.name} room ${task.id} check 已经完成`);
                room.deleteTaskById(task.id,"tower");
            }else 
            {
                // room.log("info",`${room.name} tower ${task.id} 正在执行防御塔任务`);
                break;
            }
           // global.Log.Info(`${room.name} room ${task.id} check 未完成`);
        }
    }

    protected checkState(room:Room,task:ITaskDeclare["tower"]):ETaskState
    {
        return TowerTaskChecker.check(room,task);
      
    }
    
}